<?php

namespace app\models;

use think\Model;

/**
 * Class ClassRoomTimeModel
 * @package app\models
 */
class ClassRoomTimeModel extends Model
{
    protected $table = 'edu_class_room_time';

    /**
     * 获取列表.
     *
     * @param $param
     *
     * @throws \think\Exception
     * @throws \think\exception\DbException
     *
     * @return array
     */
    public function getClassRoomTimeLists($param)
    {
        $page = isset($param['page']) ? (int) $param['page'] : 1;
        $listRows = isset($param['limit']) ? (int) $param['limit'] : 10;
        $where = [];
        if (isset($param['type']) && '' !== $param['type']) {
            if($param['type'] == 'all'){
                $where['type'] = ['in','1,0'];
            }else if($param['type'] == 'zm'){
                $where['type'] = 0;
            }else if($param['type'] == 'gzr'){
                $where['type'] = 1;
            }
        }
        if (isset($param['class_id']) && '' !== $param['class_id']) {
            $where['class_id'] = $param['class_id'];
        }
        $listData = $this->where($where)
            ->paginate($listRows, false, ['page' => $page])
            ->toArray();
        if (!empty($listData)) {
            foreach ($listData['data'] as &$item) {
                $item['start_time'] = date('H:i',strtotime($item['start_time']));
                $item['end_time'] = date('H:i',strtotime($item['end_time']));
                $item['week'] = ClassTimeModel::get($item['week'])['week'];
                $item['class_room'] = ClassRoomModel::get($item['class_room'])['class_name'];
            }
        }
        return $listData;
    }
}
